package com.vueblog.webapi.controller;


import com.vueblog.webapi.entity.UserEntity;
import com.vueblog.webapi.enums.ResponseEnum;
import com.vueblog.webapi.response.BaseResponse;
import com.vueblog.webapi.service.IUserService;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.session.Session;
import org.apache.shiro.subject.Subject;
import org.apache.shiro.web.servlet.ShiroHttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.util.Enumeration;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author luosj
 * @since 2021-05-29
 */
@Controller
@CrossOrigin
@RequestMapping("/show/bloggerStatus")
public class ShowBloggerStatusController {

    @Autowired
    private IUserService userService;

    /**
     * 判断博主是否登录
     */
    @GetMapping("/isOnLine")
    @ResponseBody
    public BaseResponse judgeBloggerisOnLine(HttpServletRequest request) {
        return userService.getIsOnLine();




//        Object attribute = request.getServletContext().getAttribute("loginCookie");
//        //获取当前会话的所有的Cookie对象
//        Cookie[] cookies = request.getCookies();
//        if(cookies != null) {
//            // 遍历cookie
//            for (Cookie cookie : cookies) {
//                if ("JSESSIONID".equals(cookie.getName())) {
//                    // 获取键为JSESSIONID的cookie值
//                    String jsessionId = cookie.getValue();
//                    if (attribute != null) {
//                        // 强转为String类型
//                        String loginCookie = (String) attribute;
//                        if (jsessionId.equals(loginCookie)) {
//                            // 如果键为JSESSIONID的cookie值 与 上下文中键为loginCookie的属性值相等，那么就表示是同一个会话
//                            return new BaseResponse(ResponseEnum.SUCCESS);
//                        }
//                    }
//                }
//            }
//        }
//        return new BaseResponse(ResponseEnum.ERROR);
    }

}
